package com.yn.module.spider.utils.constant;

import java.util.ArrayList;
import java.util.List;

public enum OptEnum {
    OpearionType_Main(OptType.OpearionType,"main","主表"),
    OpearionType_Detail(OptType.OpearionType,"detail","明细"),

    SpiderOpertion_NationMedicare_Material(OptType.SpiderOpertion, "natmc_material", "【国家医保信息业务编码标准库】国家医用耗材分类与代码"),
    SpiderOpertion_NationMedicare_MaterialDetail(OptType.SpiderOpertion, "natmc_material_detail", "国家医保信息业务编码标准库】国家医用耗材分类与代码:明细"),
    SpiderOpertion_NationMedicare_Drug(OptType.SpiderOpertion, "natmc_drug", "【国家医保信息业务编码标准库】医保药品分类与代码"),
    SpiderOpertion_NationMedicare_Serv(OptType.SpiderOpertion, "natmc_service", "【国家医保信息业务编码标准库】全国医疗服务项目"),
    SpiderOpertion_NationMedicare_MedicareMaterial(OptType.SpiderOpertion, "natmc_medicare_material", "【国家医保信息业务编码标准库】医保医用耗材分类与代码"),
    SpiderOpertion_NationMedicare_MedicareMaterialDetail(OptType.SpiderOpertion, "natmc_medicare_material_detail", "国家医保信息业务编码标准库】医保医用耗材分类与代码:明细"),


    ;
    private OptType type;
    private String value;
    private String name;

    OptEnum(OptType type, String value, String name) {
        this.type = type;
        this.value = value;
        this.name = name;
    }

    /**
     * 根据type获取name或value，
     * map name-->value 或 value-->name
     *
     * @param type
     * @return
     */
    public static List<String> getValueListByType(OptType type) {
        List<String> list = new ArrayList<>();
        OptEnum[] dictList = OptEnum.values();
        for (OptEnum dict : dictList) {
            if (type.equals(dict.type)) {
                list.add(dict.value);
            }
        }
        return list;
    }


    /**
     * 根据字符串获取enum
     *
     * @param value
     * @return
     */
    public static OptEnum getEnumByValue(OptType type, String value) {
        OptEnum[] dictList = OptEnum.values();
        for (OptEnum dict : dictList) {
            if (type.equals(dict.type) && value != null && value.equals(dict.value())) {
                return dict;
            }
        }
        return null;
    }

    /**
     * 根据名称字符串获取enum
     *
     * @param name
     * @return
     */
    public static OptEnum getEnumByName(OptType type, String name) {
        OptEnum[] dictList = OptEnum.values();
        for (OptEnum dict : dictList) {
            if (type.equals(dict.type) && name != null && name.equals(dict.getName())) {
                return dict;
            }
        }
        return null;
    }

    public String value() {
        return value;
    }

    public String getName() {
        return name;
    }
}
